{include file="common/head"/}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>
    {include file="common/left"}
    <div class="main-content">
        <div class="main-content-inner">
            {include file="common/header_nav"}

            <div class="page-content">
                <div class="page-header">
                    <h1>
                        您当前操作
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            修改会员信息
                        </small>
                    </h1>
                </div><!-- /.page-header -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form class="form-horizontal" role="form" name="memberUpdate" id="memberUpdate" method="post" action="{:url('memberUpdate')}">
                            <input type="hidden" name="member_id" value="{:input('param.member_id')}">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="group_id">所属用户组：</label>
                                <div class="col-sm-10 col-xs-12">
                                    <select name="group_id" id="group_id" class="col-select col-xs-12 col-sm-4">
                                        <option value="">请选择所属用户组</option>
                                        {foreach name="member_group" id="v"}
                                        <option value="{$v.group_id}" {if condition="$memberList['group_id'] eq $v['group_id']"}selected{/if}>{$v.name}</option>
                                        {/foreach}
                                    </select>
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span></span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="group_id">用户名：</label>
                                <div class="col-sm-10 col-xs-12">
                                    <input type="text" name="username" id="username" value="{$memberList.username}" placeholder="输入用户名" class="col-xs-12 col-md-4"/>
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>用户名必须是以字母开头，数字、符号组合</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="pwd">登录密码：</label>
                                <div class="col-sm-10 col-xs-12">
                                    <input type="password" name="pwd" id="pwd" placeholder="输入登录密码" class="col-xs-12 col-md-4"/>
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>密码必须大于6位，小于15位</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="petname">昵称：</label>
                                <div class="col-sm-10 col-xs-12">
                                    <input type="text" name="petname" id="petname" value="{$memberList.petname}"  placeholder="输入昵称" class="col-xs-12 col-md-4"/>
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span></span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="province">所在地：</label>
                                <div class="col-sm-10 col-xs-12">
                                    <select name="province" id="province" onChange="loadRegion('province',2,'city','{:url('Ajax/getRegion')}',town);">
                                        <option value="0">省份/直辖市</option>
                                        {volist name="province" id="vo"}
                                        <option value="{$vo.id}" {if condition="$memberList['province'] eq $vo['id']"}selected{/if}>{$vo.name}</option>
                                        {/volist}
                                    </select>
                                    <select name="city" id="city"  onchange="loadRegion('city',3,'town','{:url('Ajax/getRegion')}');">
                                        <option  value="0">市/县</option>

                                        {php}
                                        $city=db('Region')->where(array('pid'=>$memberList['province']))->select();
                                        {/php}
                                        {foreach name="city" item="v"}
                                        <option {if condition="$memberList['city'] eq $v['id']"}selected{/if} value="{$v.id}">{$v.name}</option>
                                        {/foreach}
                                    </select>
                                    <select name="town" id="town">
                                        <option value="0">镇/区</option>
                                        {php}
                                        $town=db('Region')->where(array('pid'=>$memberList['city']))->select();
                                        {/php}
                                        {volist name="town" id="vy"}
                                        <option {if condition="$memberList['town'] eq $vy['id']"}selected{/if} value="{$vy.id}">{$vy.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right"> 性别： </label>
                                <div class="col-sm-10 col-xs-12" style="padding-top:5px;">
                                    <label>
                                        <input name="sex" type="radio" {if condition="$memberList['sex'] eq 1"}checked{/if} value="1" checked class="ace" />
                                        <span class="lbl"> 男 </span>&nbsp;&nbsp;
                                    </label>
                                    <label>
                                        <input name="sex" type="radio" {if condition="$memberList['sex'] eq 2"}checked{/if} value="2" class="ace" />
                                        <span class="lbl"> 女 </span>
                                    </label>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="tel"> 手机号码：</label>
                                <div class="col-sm-10 col-xs-12">
                                    <input type="text" name="tel" id="tel" value="{$memberList.tel}" placeholder="输入手机号码" class="col-xs-12 col-md-4" />
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>只能填写数字</span>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="email"> 联系邮箱：</label>
                                <div class="col-sm-10 col-xs-12">
                                    <input type="text" name="email" id="email" value="{$memberList.email}" placeholder="输入联系邮箱" class="col-xs-12 col-md-4" />
                                    <span class="lbl">&nbsp;&nbsp;<span class="red">*</span>必填：用于找回密码</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="open"> 是否审核： </label>
                                <div class="col-sm-10 col-xs-12" style="padding-top:5px;">
                                    <label>
                                        <input name="open" id="open" value="1" {if condition='$memberList["open"] eq 1'}checked{/if} class="ace ace-switch ace-switch-5" type="checkbox">
                                        <span class="lbl">&nbsp;&nbsp;默认关闭</span>
                                    </label>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-2 col-md-10">
                                    <button class="btn btn-info" type="submit">
                                        <i class="ace-icon fa fa-check bigger-110"></i>
                                        提交
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset">
                                        <i class="ace-icon fa fa-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {include file="common/foot" /}
</div>
<script type="text/javascript" src="__STATIC__/assets/js/region.js"></script>
<script>
    $(function(){
        $('#memberUpdate').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){

            if( '' == $(".selector").val()){
                layer.alert('会员所属用户组必须选择', {icon: 5}, function(index){
                    layer.close(index);
                    $('.selector').focus();
                });
                return false;
            }

            if( '' == $("#username").val()){
                layer.alert('登录用户名不能为空', {icon: 5}, function(index){
                    layer.close(index);
                    $('#username').focus();
                });
                return false;
            }

            if( $.trim($('#pwd').val()).length > 0 && $.trim($('#pwd').val()).length < 6 || $.trim($('#pwd').val()).length >15 ){
                layer.alert('登录密码位数不能少于6位或者大于15位', {icon: 5}, function(index){
                    layer.close(index);
                    $('#pwd').focus();
                });
                return false;
            }

            if( '' == $.trim($('#petname').val())){
                layer.alert('昵称不能为空', {icon: 5}, function(index){
                    layer.close(index);
                    $('#petname').focus();
                });
                return false;
            }

            if (!$("#tel").val().match(/^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/)) {
                layer.alert('电话号码格式不正确', {icon: 5}, function(index){
                    layer.close(index);
                    $('#tel').focus();
                });
                return false;
            }

            if(!$("#email").val().match(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/)){
                layer.alert('邮箱格式不正确', {icon: 5}, function(index){
                    layer.close(index);
                    $('#tel').focus();
                });
                return false;
            }
        }
        function complete(data){
            if(data.status==1){
                layer.alert(data.info, {icon: 6}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
            }else{
                layer.alert(data.info, {icon: 5}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

    });
</script>
</body>
</html>